package edu.maping.easy.sequence.ticker;

import java.util.List;

import processing.core.PApplet;
import processing.xml.XMLElement;
import edu.maping.easy.editor.EasyMappingEditor;
import edu.maping.easy.editor.EditManager;
import edu.maping.easy.gui.Button;
import edu.maping.easy.gui.ButtonList;
import edu.maping.easy.gui.GUIEvent;
import edu.maping.easy.gui.GuiFactory;
import edu.maping.easy.gui.ScreenLogger;
import edu.maping.easy.model.GUIInteraction;
import edu.maping.easy.model.Thing;
import edu.maping.easy.sequence.ActionEventList;
import edu.maping.easy.sequence.SequenceStep;

public class PropagationTicker implements Ticker {

	private long moment = 0;
	private long delay = 0;
	private boolean toTrigger = false;
	private boolean newMoment = false;

	@Override
	public String getName() {
		return null;
	}

	@Override
	public boolean isReadyToNewTicker() {
		return false;
	}

	@Override
	public boolean isTrigerred() {
		boolean ret = toTrigger;
		if (ret) {
			toTrigger = false;
			newMoment = false;
		}
		return ret;
	}

	@Override
	public Ticker newTicker() {
		return null;
	}

	@Override
	public boolean setReadyToNewTicker() {
		return false;
	}

	@Override
	public void updateTrigger(PApplet pApplet, Thing thing) {

		if (newMoment) {
			long now = pApplet.frameCount;
			if (now > (moment + delay)) {
				toTrigger = true;
				newMoment = false;
			}
		}
	}

	public void setPropagationMoment(long moment) {
		newMoment = true;
		this.moment = moment;
	}

	public void setDelay(long delay) {
		this.delay = delay;
	}

	public void desXmlIzation(XMLElement seqsElement) {

		String delayCad = seqsElement.getAttribute("delay");
		delay = Long.parseLong(delayCad);

	}

	public XMLElement xmlIzation() {

		XMLElement seqsElement = new XMLElement();
		seqsElement.setName("Ticker");
		seqsElement.setAttribute("delay", "" + delay);

		return seqsElement;
	}
}
